package JUC;

/**
 * @author 豆包LU
 * @date 2023/5/23 11:38
 */
public class OrderedThreadExecution {
    public static void main(String[] args) {
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("T1");
            }
        });

        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    t1.join(); // 等待t1执行完毕
                    System.out.println("T2");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    t2.join(); // 等待t2执行完毕
                    System.out.println("T3");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        // 启动线程
        t1.start();
        t2.start();
        t3.start();
    }
}
